﻿using System;
using System.Collections.Generic;
using DapperExtensions;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ET_DbCommon.DAL;
using Newtonsoft.Json;

namespace ET_DbCommon.Model
{
    [Table("post")]
    public class postModel
    {
        public string post_id { get; set; }

        public string post_name { get; set; }

        public string remark { get; set; }

        public int create_by { get;set; }

        public DateTime create_time { get; set; }

        public string update_by { get; set; }

        public DateTime update_time { get; set; }
        public static postModel MyPostModel { get => myPostModel; set => myPostModel = value; }

        #region
        [JsonIgnore]
        private static postModel myPostModel = null;

        public List<postModel> MyPostModelList= new List<postModel>();
        public static postModel Instance()
        {
            if (MyPostModel == null)
                MyPostModel = new postModel();
            return MyPostModel;
        }

        public List<postModel> GetPostModelList()
        {
            if(MyPostModelList!=null&& MyPostModelList.Count>0)
                return MyPostModelList;
            MyPostModelList = PostDAL.GetPostInfo();
            return MyPostModelList;
        }
        public string GetPostInfoDetail(string postId)
        {
            string RoleInfo = string.Empty;
            if(postId!=null&& postId!=string.Empty)
            {
                if(postId.Contains(","))
                {
                    var PostList= postId.Split(',').ToList();
                    foreach(var post in  PostList)
                    {
                        RoleInfo += GetPostModelList().FirstOrDefault(T => T.post_id == post).post_name + ",";
                    }
                }
                else
                {
                    RoleInfo = GetPostModelList().FirstOrDefault(T => T.post_id == postId).post_name;
                }
            }
            return RoleInfo;
        }

        #endregion
    }
}
